﻿using System;
using Ue.CQRS.Bus;
using Ue.CQRS.Configuration;

namespace Ue.CQRS.Ioc
{
    public class DefaultContainer : IContainer
    {
        private IBus bus;
        private IConfiguration configuration;
        private IContainer container;

        public DefaultContainer(IConfiguration configuration, IContainer container)
        {
            this.configuration = configuration;
            this.container = container;
        }

        public bool IsRegistered(Type type)
        {
            return this.container != null
                ? this.container.IsRegistered(type)
                : false;
        }


        public T Resolve<T>() where T : class
        {
            var type = typeof(T);
            if (type == typeof(IBus))
            {
                return (T)this.bus;
            }

            return this.container != null
                ? this.container.Resolve<T>()
                : default(T);
        }
    }
}
